getTime2Percent = function (duration, curTime) {
    // console.log(curTime);
    let sp = curTime.split(":");
    // console.log(sp)
    let curSec = parseInt(sp[0] * 3600) + parseInt(sp[1] * 60) + parseFloat(sp[2]);
    // console.log(curSec)
    return Math.ceil(100 / duration * curSec);
};

formatTodayTime = function (timestamp) {
    var time = new Date(timestamp);
    var m = time.getMonth() + 1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
};

//计算日期差


function formatDuring(mss) {
    if (mss <= 1000) {
        return "0.00";
    }
    var days = parseInt(mss / (1000 * 60 * 60 * 24));
    var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = parseInt((mss % (1000 * 60)) / 1000);
    let str = "";
    if (days > 0) {
        str += days + "天";
    }
    if (hours > 0) {
        str += hours + "小时";
    }
    if (minutes > 0) {
        str += minutes + "分";
    }
    if (seconds && seconds > 0) {
        str += seconds + "秒";
    }
    return str.trim().length == 0 ? "0.00" : str;
}

function add0(m) {
    return m < 10 ? '0' + m : m
}



module.exports = {
    getTime2Percent,
    formatTodayTime,
    formatDuring,
};
